package tests;

import static org.junit.Assert.assertEquals;
import model.HostAddress;
import model.IPAddress;
import model.Octet;
import model.Subnet;

import org.junit.Test;

public class NetworkObjectTest {

	private IPAddress ip;
	private Octet[] addresses;
	private HostAddress network;

	public NetworkObjectTest() {
		generateIpAdressFromOctet();
		setupNetwork();

	}

	public void setupNetwork() {
		IPAddress ip = new IPAddress("127.16.200.1");

		network = new HostAddress(ip, "mein erstes Netzwerk");
		Subnet subnet = new Subnet(new IPAddress("172.16.200.3"), 128, null);
		Subnet subnet2 = new Subnet(new IPAddress("172.16.200.4"), 24, "");
		subnet.editIpAddress(new IPAddress("172.16.200.11"), "neuer Platz");

		network.getSubnetList().add(subnet);
		network.getSubnetList().add(subnet2);
	}

	public void generateIpAdressFromOctet() {
		addresses = new Octet[4];
		addresses[0] = new Octet(255);
		addresses[1] = new Octet(254);
		addresses[2] = new Octet(253);
		addresses[3] = new Octet(252);

		ip = new IPAddress(addresses);

	}

	@Test
	public void getAddressFromIP() {

		assertEquals("255.254.253.252", ip.getAddress());
	}

	@Test
	public void getAddressBitsFromIP() {

		assertEquals(addresses[0], ip.getAddressBits()[0]);
	}

	@Test
	public void testNetwork() {
		assertEquals("127.16.200.1", network.getHostAddress().getAddress());
		assertEquals("mein erstes Netzwerk", network.getName());

	}

	@Test
	public void testSubnet() {
		Subnet s = network.getSubnetList().get(0);
		assertEquals("255.255.255.0", s.getMask().getAddress());
		assertEquals("172.16.200.3", s.getNetAdress().getAddress());
		assertEquals(24, s.getSuffix());

	}

	@Test
	public void testSubnet2() {
		Subnet s = network.getSubnetList().get(1);
		assertEquals("255.255.255.0", s.getMask().getAddress());
		assertEquals("172.16.200.4", s.getNetAdress().getAddress());
		assertEquals(24, s.getSuffix());

	}

	@Test
	public void testIpAddress() {
		Subnet s = network.getSubnetList().get(0);
		IPAddress ip = s.getIpAddressList().get(0);
		assertEquals("172.16.200.11", ip.getAddress());

	}

}
